package cn.acewill.yxd.yunxundian.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.xiao.nicevideoplayer.NiceVideoPlayer;
import com.xiao.nicevideoplayer.NiceVideoPlayerManager;
import com.xiao.nicevideoplayer.TxVideoPlayerController;

import java.util.List;

import cn.acewill.yxd.yunxundian.R;

/**
 * Created by XXX on 2017/9/18.
 */

public class newVideoAdapter extends BaseAdapter{

    private Context context;
    private List<String> list;

    public newVideoAdapter( Context context, List<String> list){
        this.context=context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        viewHolder holder ;
        if (convertView==null){
           convertView= LayoutInflater.from(context).inflate(R.layout.look_video_play_view,parent,false);
            holder=new viewHolder();
            holder.myVideo= (NiceVideoPlayer) convertView.findViewById(R.id.NcVideo);
            convertView.setTag(holder);
        }else{
            holder= (viewHolder) convertView.getTag();
        }
        String path = list.get(position);

        if (holder.myVideo!=null){
            NiceVideoPlayerManager.instance().releaseNiceVideoPlayer();
        }
        holder.myVideo.setPlayerType(NiceVideoPlayer.TYPE_IJK);
        holder.myVideo.setUp(path,null);
        TxVideoPlayerController controller = new TxVideoPlayerController(context);
        String[] name=path.split("\\/");
        String[] thisname=name[name.length-1].split("\\_");
        if (thisname.length>=3){
            controller.setTitle(thisname[2]+thisname[3]);
        }else{
            controller.setTitle("");
        }
     //   controller.setTitle(name);
        holder.myVideo.setController(controller);
        holder.myVideo.setBackgroundColor(Color.BLACK);

        //load缩略图


        return convertView;
    }

    class viewHolder{
        NiceVideoPlayer myVideo;
    }
}
